/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.server;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.lucava.boatskeeper.shared.Boat;
import org.lucava.boatskeeper.shared.User;

/**
 *
 * @author glenn
 */
public class MockUserDao {

    final static Map<Integer, User> users = new HashMap<Integer, User>();

    static {
        for (int i = 0; i < 10; i++) {
            User u = new User();
            u.setId(i);
            u.setLogin("user" + i);
            u.setRoleName("role" + i);
            u.setRoleId(i);
            users.put(i, u);
        }
    }

    public static void add(User u) {
        u.setId(users.size() - 1);
        u.setRoleName(MockRoleDao.get(u.getRoleId()).getName());

        users.put(u.getId(), u);
    }

    public static void save(User u) {
        users.get(u.getId()).setLogin(u.getLogin());
        users.get(u.getId()).setRoleName(MockRoleDao.get(u.getRoleId()).getName());
        users.get(u.getId()).setRoleId(u.getRoleId());
    }

    public static void delete(User u) {

        users.remove(u.getId());
    }

    public static User get(Integer id) {
        return users.get(id);
    }

    public static List<User> getAll() {

        return new ArrayList<User>(users.values());
    }
}
